home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / dvivga9.zip / FONTSUB.H < prev    next >
Text File  |  1988-05-30  |  5KB  |  151 lines

  1. /* -*-C-*- fontsub.c */
  2. /*-->fontsub*/
  3. /**********************************************************************/
  4. /****************************** fontsub *******************************/
  5. /**********************************************************************/
  6. BOOLEAN
  7. fontsub(subfont,submag,TeXfont,TeXmag)
  8. char *subfont;        /* new fontname returned */
  9. int  *submag;        /* new magnification returned (0 if entire family) */
  10. char *TeXfont;        /* TeX requested fontname */
  11. int TeXmag;        /* TeX requested magnification value */
  12.  
  13. /***********************************************************************
  14.  
  15. Given a  TeX  fontname  and  a  magnification  value,  search  the  font
  16. substitution file (if  any) for  the first pattern  defining a  possible
  17. replacement, and return  their values  in subfont[] and  submag, with  a
  18. function value of TRUE.   If no substitution  is possible, subfont[]  is
  19. set to a null string, submag to 0, and the function value to FALSE.
  20.  
  21. The substitution file is searched for under the names
  22.  
  23.     (1) subfile (by default, or from command line)
  24.     (2) subname subext
  25.     (3) subpath subname subext
  26.  
  27. allowing the user to have document-file specific substitutions, TeX-wide
  28. private substitutions, and system TeX-wide substitutions.  For  example,
  29. these     files      might    be     "sample.sub",      "texfonts.sub",    and
  30. "texinputs:texfonts.sub" for a document "sample.tex".
  31.  
  32. Font substitution lines have the form:
  33.  
  34. % comment
  35. oldname.oldmag    ->    subname.submag    % comment
  36. oldname oldmag    ->    subname submag    % comment
  37. oldname     ->    subname        % comment
  38.  
  39. Examples are:
  40.  
  41. % These provide replacements for some LaTeX invisible fonts:
  42. iamr10 1500    ->    amr10 1500    % comment
  43. iamr10.1500    ->    amr10.1500    % comment
  44. iamssb8        ->    amssb8        % comment
  45.  
  46. These are  easily readable  by sscanf().   The first  two forms  request
  47. substitution of a  particular font  and magnification.     The third  form
  48. substitutes an entire font  family; the closest available  magnification
  49. to the required one will be  used.  Any dots in the non-comment  portion
  50. will be converted  to spaces, and  therefore, cannot be  part of a  name
  51. field.
  52.  
  53. The first  matching substitution  will  be selected,  so  magnification-
  54. specific  substitutions   should   be    given    first,     before   family
  55. substitutions.
  56.  
  57. Comments are introduced by percent and continue to end-of-line, just  as
  58. for TeX.   One  whitespace character  is  equivalent to  any  amount  of
  59. whitespace.  Whitespace and comments are optional.
  60. ***********************************************************************/
  61.  
  62. {
  63.     static FILE* subfp = (FILE *)NULL;    /* file pointer for sub file */
  64.     static BOOLEAN have_file = TRUE;    /* memory of open success */
  65.     char line[MAXSTR];            /* for sub file lines */
  66.     char *pline;            /* pointer to line[] */
  67.     static char fname[MAXFNAME];    /* sub file name */
  68.     char oldfont[MAXFNAME];        /* working storage for font names */
  69.     int oldmag;                /* font magnification */
  70.     int k;                /* sscanf() result */
  71.     int line_number;            /* for error messages */
  72.  
  73.     if (!have_file)            /* no file available */
  74.     {
  75.     *subfont = '\0';
  76.     *submag = 0;
  77.     return (FALSE);
  78.     }
  79.     else if (subfp == (FILE *)NULL)    /* happens only first time  */
  80.     {
  81.     (void)strcpy(fname,subfile);    /* try document specific: */
  82.     subfp = fopen(fname,"r");    /* e.g. foo.sub (from foo.dvi) */
  83.     DEBUG_OPEN(subfp,fname,"r");
  84.     if (subfp == (FILE *)NULL)
  85.     {
  86.         (void)strcpy(fname,subname);/* try path specific: */
  87.         (void)strcat(fname,subext);    /* e.g. texfonts.sub */
  88.         subfp = fopen(fname,"r");
  89.         DEBUG_OPEN(subfp,fname,"r");
  90.     }
  91.  
  92.     if (subfp == (FILE *)NULL)
  93.     {
  94.         (void)strcpy(fname,subpath);/* try system specific: */
  95.         (void)strcat(fname,subname);/* e.g. texinputs:texfonts.sub */
  96.         (void)strcat(fname,subext);
  97.         subfp = fopen(fname,"r");
  98.         DEBUG_OPEN(subfp,fname,"r");
  99.     }
  100.  
  101.     if (subfp == (FILE *)NULL) /* could not open any substitution file */
  102.     {
  103.         have_file = FALSE;
  104.         *subfont = '\0';
  105.         *submag = 0;
  106.         return (FALSE);
  107.     }
  108.     }
  109.  
  110.     line_number = 0;
  111.     (void)REWIND(subfp);
  112.     while (fgets(line,MAXSTR,subfp) != (char *)NULL)
  113.     {
  114.     line_number++;        /* count lines */
  115.  
  116.     pline = &line[0];    /* truncate at comment start or end-of-line */
  117.     while ((*pline) && (*pline != '%') &&
  118.         (*pline != '\r') && (*pline != '\n'))
  119.     {
  120.         if (*pline == '.')    /* convert dots to whitespace for sscanf() */
  121.         *pline = ' ';
  122.         ++pline;
  123.     }
  124.     *pline = '\0';        /* replace terminator by NUL */
  125.  
  126.     if ((k = (int)sscanf(line," %s %d -> %s %d",oldfont,&oldmag,
  127.         subfont,submag)) == 4)
  128.     {
  129.         if ((TeXmag == oldmag) && (strcm2(oldfont,TeXfont) == 0))
  130.         return (TRUE);
  131.     }
  132.     else if ((k = (int)sscanf(line," %s -> %s",oldfont,subfont)) == 2)
  133.     {
  134.         *submag = 0;
  135.         if (strcm2(oldfont,TeXfont) == 0)
  136.         return (TRUE);
  137.     }
  138.     else if (k != EOF)    /* EOF means no fields, so have empty line */
  139.     {
  140.         (void)sprintf(message,
  141.         "fontsub():  Bad font substitution at line %d in file \
  142. [%s]: [%s]",
  143.         line_number,fname,line);
  144.         (void)warning(message);
  145.     }
  146.     }
  147.     *subfont = '\0';
  148.     *submag = 0;
  149.     return (FALSE);
  150. }
  151.